package com.hns.can.report.service;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.report.entity.TBsStatProbAnaEntity;
import com.hns.can.report.vo.CarProblemAnalysisVo;
import com.hns.can.report.vo.QualityIndexParamVo;
import com.hns.frame.enumrate.MsgType;
import com.hns.frame.exception.BusinessException;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 车辆问题分析Service
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class CarQuestionAnlsService extends CommonService {

    /**
     * 分页查询车辆问题
     * @param vo
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @Transactional
    @LeftOrgAnnotation
    public Pagination searchTBsStatProbAnaPage(QualityIndexParamVo vo) throws Exception {
        Pagination page = this.myBatisPage("qualityIndex.getTBsStatProbAnaCnt","qualityIndex.getTBsStatProbAnaList", vo, TBsStatProbAnaEntity.class);
        return page;
    }


    /**
     * 查询车辆问题用于导出
     * @param vo
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @Transactional
    @LeftOrgAnnotation
    public List<TBsStatProbAnaEntity> searchTBsStatProbAnaList(QualityIndexParamVo vo)throws Exception {
        List<TBsStatProbAnaEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("qualityIndex.getTBsStatProbAnaList", vo), TBsStatProbAnaEntity.class);
        if(PubUtil.isEmpty(list)){
            throw new BusinessException(MsgType.WARN.getFlag(), "没有数据导出！");
        }
        return list;
    }
    

    /**
     * 车辆问题分析统计信息
     * @param vo
     * @throws Exception
     * @author:Chenl
     * @email:
     */
    @Transactional
    @LeftOrgAnnotation
    public List<CarProblemAnalysisVo> getCarProblemPage(QualityIndexParamVo vo) throws Exception {
    	int count = (int) sqlMapDao.selectOne("qualityIndex.checkDenominator", vo);
    	if(count == 0){
    		return null;
    	}
//        Pagination page = this.myBatisPage("qualityIndex.getCarProblemCnt","qualityIndex.getCarProblemPage", vo, CarProblemAnalysisVo.class);
//        return page;
    	List<CarProblemAnalysisVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("qualityIndex.getCarProblemPage", vo), CarProblemAnalysisVo.class);
    	return list;
    }
}
